#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define pii pair<int,int>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
using namespace std;

void inline solve();

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);

    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);

    int t=1;cin >> t;
    while(t--) solve();
    return 0;
}

const int N=1e5+10,M=1e6+10;
int n,m,L,V,v[N],a[N],l[N],r[N],p[N],s[M],res1,res2;
multiset<int> st;
vector<pii> tmp,qj;
bool cmp(pii x,pii y){
    if(x.fi!=y.fi) return x.fi<y.fi;
    else return x.se>y.se;
}
void inline solve(){
    cin >> n >> m >> L >> V;
    for(int i=1;i<=n;i++){
        cin >> l[i] >> v[i] >> a[i];
        if(a[i]<0){
            int s=(V*V-v[i]*v[i])/(2*a[i]);
            if(s*2*a[i]==V*V-v[i]*v[i]) s--;
            r[i]=min(l[i]+s,L);
        }else if(a[i]==0){
            r[i]=L;
        }else if(a[i]>0){
            int s=(V*V-v[i]*v[i])/(2*a[i])+1;
            l[i]=max(l[i]+s,l[i]);
            r[i]=L;
        }
    }
    for(int i=0;i<=L;i++) s[i]=0;
    for(int i=1;i<=m;i++){
        cin >> p[i];
        s[p[i]]++;
    }
    for(int i=1;i<=L;i++) s[i]+=s[i-1];
    tmp.clear();
    res1=0;
    for(int i=1;i<=n;i++){
        if(l[i]>r[i] || a[i]==0 && v[i]<=V) continue;
        if(s[r[i]]-(l[i]==0?0:s[l[i]-1])>0){
            res1++;
            tmp.pb(mp(l[i],r[i]));
            st.insert(r[i]);
        }
    }
    cout << res1 << " ";
    qj.clear();
    sort(tmp.begin(),tmp.end(),cmp);
    for(auto x:tmp){
        st.erase(st.find(x.se));
        if(st.empty() || (*st.begin())>x.se){
            qj.pb(x);
        }
    }
    res2=0;
    sort(qj.begin(),qj.end());
    for(int i=0,j=0;i<qj.size();i++){
        if(!j || p[j]<qj[i].fi){
            res2++;
            while(j+1<=m && p[j+1]<=qj[i].se){
                j++;
            }
        }
    }
    cout << m-res2 << endl;
}